package com.prince.web.base;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import com.prince.constant.Constants;
import com.prince.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.prince.page.Page;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public abstract class BaseController {

	protected   Logger logger = LoggerFactory.getLogger(BaseController.class);

	protected Page getRequestPageRollInfo(Map<String, Object> params) {
		if (null == params || params.size() == 0) {
			logger.debug("[BaseController] getRequestPageRollInfo request params is null");
			return null;
		}
		Integer start = Integer.parseInt(params.get("page").toString());
		Integer length = Integer.parseInt(params.get("rows").toString());
		return new Page((start - 1) * length, length);
	}


	@InitBinder
	protected void initBinder(WebDataBinder binder) {
		binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
		// binder.registerCustomEditor(int.class, new CustomNumberEditor(int.class,
		// true));
		// binder.registerCustomEditor(int.class, new IntegerEditor());
		// binder.registerCustomEditor(long.class, new CustomNumberEditor(long.class,
		// true));
		// binder.registerCustomEditor(long.class, new LongEditor());
		// binder.registerCustomEditor(double.class, new DoubleEditor());
		// binder.registerCustomEditor(float.class, new FloatEditor());
	}
}
